
#include <cstdio>
#include <cstring>
#include "parser.h"
#include "vm.h"
#include "core.h"

#define MAX_LINE_LEN 1024

//执行脚本文件
static void RunFile(const char* path) {
    const char* lastSlash = strrchr(path, '/');
    if (lastSlash != nullptr) {
        char* root = (char*)malloc(lastSlash - path + 2);
        memcpy(root, path, lastSlash - path + 1);
        root[lastSlash - path + 1] = '\0';
        rootDir = root;
    }

    VM *vm = new VM();
    BuildCore(vm);

    const char *sourceCode = ReadFile(path);
    ObjString pathStr = *new ObjString(vm, path, strlen(path));
    ExecuteModule(vm, OBJ_TO_VALUE(&pathStr), sourceCode);
}

int main(int argc, const char *argv[]) {
    if (argc == 1) {
        //RunCli();
    } else {
        RunFile(argv[1]);
    }
    return 0;
}
